<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>审批假条</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{../../lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{../../css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">


    <div class="layui-form-item">
        <label class="layui-form-label required">审批结果选择</label>
        <div class="layui-input-block">
            <input type="text" th:field="${leave.id}" style="display: none"/>
            <input type="radio" name="status" value="1" title="通过" th:checked="${leave.status==1}"><div class="layui-unselect layui-form-radio layui-form-radioed">
            <i class="layui-anim layui-icon layui-anim-scaleSpring"></i><div>通过</div></div>
            <input type="radio" name="status" value="-1" title="未通过" th:checked="${leave.status==-1}"><div class="layui-unselect layui-form-radio">
            <i class="layui-anim layui-icon"></i><div>未通过</div></div>
            <input type="radio" name="status" value="0" title="待审批" th:checked="${leave.status==0}"><div class="layui-unselect layui-form-radio layui-radio">
            <i class="layui-anim layui-icon"></i><div>待审批</div></div>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">审批原因</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" th:field="*{leave.endmessage}" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">审批</button>
        </div>
    </div>
</div>
<script th:src="@{../../lib/layui/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        form.on('submit(saveBtn)', function (data) {
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            $("#btn-submit").attr("disabled", "disabled").addClass("layui-btn-disabled");
            //提交数据
            var url = "/leave/update";
            $.post(url, data.field, function (res) {
                console.log(res);
                if (res.code === 0) {
                    //成功提示
                    layer.msg(res.message, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        //关闭窗口,刷新数据表格
                        parent.refreshTable();
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                } else {
                    $("#btn-submit").removeAttr("disabled", "disabled").removeClass("layui-btn-disabled");
                    //失败则提示错误消息,窗口不关闭
                    layer.msg('考勤修改失败,请联系管理员', {
                        icon: 2,
                        time: 2000, //2秒关闭（如果不配置，默认是3秒）
                        anim: 6
                    }, function () {
                        //do something
                    });
                }
            })
            //关掉窗口并刷新
            //失败则提示错误信息
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</body>
</html>